home *** CD-ROM | disk | FTP | other *** search
/ Resource for Source: C/C++ / Resource for Source - C-C++.iso / misc_src / cslib16b / demo / address / csaddio.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-01  |  7.8 KB  |  211 lines

  1. #include "ctype.h" 
  2. #include "csa.h" 
  3. #include "csdb.h" 
  4.  
  5. #define NAME_LENGTH     40 
  6. #define ADRE_LENGTH     32 
  7. #define CITY_LENGTH     23 
  8. #define COUNT_LENGTH     32 
  9. #define ZIP_LENGTH     9 
  10. #define TEL_LENGTH     17 
  11. #define RELATION_LENGTH     10 
  12. #define INFO_LENGTH     70 
  13.  
  14. ////////// Indexes to be used with the 'order()' function./////////////
  15. #define UNSORTED     0
  16. #define NAME_INDEX     1 
  17. #define CITY_INDEX     2 
  18. #define BIRTH_INDEX     3 
  19. #define RELATION_INDEX     4 
  20.  
  21. typedef struct 
  22. {
  23.    char   _name[NAME_LENGTH+1]; 
  24.    char   _adre[ADRE_LENGTH+1]; 
  25.    char   _city[CITY_LENGTH+1]; 
  26.    char   _count[COUNT_LENGTH+1]; 
  27.    char   _zip[ZIP_LENGTH+1]; 
  28.    char   _tel[TEL_LENGTH+1]; 
  29.    long   __update; 
  30.    long   __birth; 
  31.    char   _relation[RELATION_LENGTH+1]; 
  32.    char   _info[INFO_LENGTH+1]; 
  33. } record;
  34.  
  35. class NAM_foundation
  36. {
  37.  protected:
  38.  
  39.    record rec;
  40.    record *recp;
  41.  
  42.    long current;
  43.    int  dirty;
  44.    int  is_open;
  45.    int  iOrder;
  46.  
  47.  
  48.    int  (NAM_foundation::*bof_fun)(void);
  49.    int  (NAM_foundation::*eof_fun)(void);
  50.    int  (NAM_foundation::*skip_fun)(int delta);
  51.    void (NAM_foundation::*top_fun)(void);
  52.    void (NAM_foundation::*bottom_fun)(void);
  53.    int  (NAM_foundation::*search_fun)(void *k);
  54.  
  55.    TBASE  db;
  56.    BTREEa in1;        //Index on field name  
  57.    BTREEa in2;        //Index on field city  
  58.    BTREEl in3;        //Index on field birth  
  59.    BTREEa in4;        //Index on field relation  
  60.  
  61.    DATE  _update;
  62.    DATE  _birth;
  63.  
  64.    int bof0(void)    { return (current==1); }
  65.    int bof1(void)    { return in1.tBOF(); }
  66.    int bof2(void)    { return in2.tBOF(); }
  67.    int bof3(void)    { return in3.tBOF(); }
  68.    int bof4(void)    { return in4.tBOF(); }
  69.  
  70.    int eof0(void)    { return (current==db.numrec()); }
  71.    int eof1(void)    { return in1.tEOF(); }
  72.    int eof2(void)    { return in2.tEOF(); }
  73.    int eof3(void)    { return in3.tEOF(); }
  74.    int eof4(void)    { return in4.tEOF(); }
  75.  
  76.    void top0(void)    { current=1; }
  77.    void top1(void)    { in1.min_dat(¤t); }
  78.    void top2(void)    { in2.min_dat(¤t); }
  79.    void top3(void)    { in3.min_dat(¤t); }
  80.    void top4(void)    { in4.min_dat(¤t); }
  81.  
  82.    void bottom0(void)    { current=db.numrec(); }
  83.    void bottom1(void)    { in1.max_dat(¤t); }
  84.    void bottom2(void)    { in2.max_dat(¤t); }
  85.    void bottom3(void)    { in3.max_dat(¤t); }
  86.    void bottom4(void)    { in4.max_dat(¤t); }
  87.  
  88.    int  search0(void * )    { return TRUE; } 
  89.    int  search1(void *k)    { return in1.search_dat_ge(k,¤t); }
  90.    int  search2(void *k)    { return in2.search_dat_ge(k,¤t); }
  91.    int  search3(void *k)    { return in3.search_dat_ge(k,¤t); }
  92.    int  search4(void *k)    { return in4.search_dat_ge(k,¤t); }
  93.  
  94.    int  skip0(int delta); 
  95.    int  skip1(int delta)    { return in1.skip_dat(delta,¤t); }
  96.    int  skip2(int delta)    { return in2.skip_dat(delta,¤t); }
  97.    int  skip3(int delta)    { return in3.skip_dat(delta,¤t); }
  98.    int  skip4(int delta)    { return in4.skip_dat(delta,¤t); }
  99.  
  100.    void in1_ins_tok(void *s)    { in1.insert(s,¤t); }
  101.    void in1_del_tok(void *s)    { in1.delet(s,¤t); }
  102.  
  103.    void tokenize(char *s,void(NAM_foundation::*fun)(void *));
  104.  
  105.  public:
  106.  
  107.  //////////////////////////////// class constructor ////////////////////////////
  108.    NAM_foundation(void); 
  109.  
  110.  //////////////////////////////// class destructor /////////////////////////////
  111.    ~NAM_foundation(void)  { close(); }
  112.  
  113.  //////////////////////////////// current record number ////////////////////////
  114.    long curr_rec(void)   { return current; }
  115.  
  116.  //////////////////////////////// define ///////////////////////////////////////
  117.    void define(void);  
  118.  
  119.  //////////////////////////////// open & close ////////////////////////////////
  120.    void open(void);  
  121.    void close(void);  
  122.  
  123.  //////////////////////////////// delete //////////////////////////////////////
  124.    int  is_delet(void)  { return db.is_delet(current); } 
  125.    void undelet(void)   { db.undelet(current); }         
  126.    void delet(void)     { db.delet(current); }           
  127.  
  128.    int  is_delet(long n) { return db.is_delet(n); } 
  129.    void undelet(long n)  { db.undelet(n); }         
  130.    void delet(long n)    { db.delet(n); }           
  131.  
  132.  //////////////////////////////// number of records ///////////////////////////
  133.    long numrec(void)         { return db.numrec(); } 
  134.  
  135.  //////////////////////////////// import/export ///////////////////////////////
  136.    int  import(char *s);
  137.    int  export(char *s);
  138.    int  to_DBASE(char *s);
  139.  
  140.  //////////////////////////////// read/write current record ///////////////////
  141.  
  142.    void write_rec2(void);
  143.    void write_rec(void) { if(dirty) write_rec2(); }
  144.  
  145.    void read_rec(void) 
  146.    {
  147.         recp=(record *)db.locate_rec(current); 
  148.         rec=*recp; 
  149.         _update.sem_jul(rec.__update); 
  150.         _birth.sem_jul(rec.__birth); 
  151.    }
  152.  
  153.  //////////////////////////////// reindexing //////////////////////////////////
  154.    void reindex(void); 
  155.  
  156.  //////////////////////////////// append //////////////////////////////////////
  157.    void append(void);        //Indexes are NOT updated.
  158.    void append_blank(void);  //Indexes ARE updated.
  159.  
  160.  //////////////////////////////// data in header //////////////////////////////
  161.    int data_2_header(void *p,U16 size) { return db.data_2_header(p,size); } 
  162.    int header_2_data(void *p,U16 size) { return db.header_2_data(p,size); } 
  163.    U16 max_data_in_header(void)        { return db.max_data_in_header();  } 
  164.  
  165.  //////////////////////////////// pack ////////////////////////////////////////
  166.    void pack(void);
  167.  
  168.  //////////////////////////////// (change) active index ///////////////////////
  169.    void order(int nr);    
  170.    int  order(void)  { return iOrder; } 
  171.  
  172.  //////////////////////////////// testing begin/end ///////////////////////////
  173.    int  tBOF(void)       { return (this->*bof_fun)(); } 
  174.    int  tEOF(void)       { return (this->*eof_fun)(); } 
  175.  
  176.  //////////////////////////////// relocating //////////////////////////////////
  177.    int  skip(int del); 
  178.    void bottom(void)     { write_rec(); (this->*bottom_fun)(); read_rec(); }  
  179.    void top(void)        { write_rec(); (this->*top_fun)(); read_rec(); }  
  180.    void search(void *k)  { write_rec(); if(!(this->*search_fun)(k)) bottom(); read_rec(); }
  181.    void go_to(long n);
  182.  
  183.  /////////////////////////reading fields //////////////////////////////////////
  184.     char * name(void)           { return rec._name; } 
  185.     char * adre(void)           { return rec._adre; } 
  186.     char * city(void)           { return rec._city; } 
  187.     char * count(void)          { return rec._count; } 
  188.     char * zip(void)            { return rec._zip; } 
  189.     char * tel(void)            { return rec._tel; } 
  190.     char * update(void)         { return (char *)_update; } 
  191.     char * birth(void)          { return (char *)_birth; } 
  192.     char * relation(void)       { return rec._relation; } 
  193.     char * info(void)           { return rec._info; } 
  194.  
  195.  /////////////////////////writing fields //////////////////////////////////////
  196.  // Note: when writing strings there are NO checks on the 
  197.  //       length. A string which is longer then the definition 
  198.  //       of the field indicates, will OVERWRITE other data!!     
  199.  //   
  200.     void   name(char *s)        { strcpy(rec._name,s); dirty=TRUE; } 
  201.     void   adre(char *s)        { strcpy(rec._adre,s); dirty=TRUE; } 
  202.     void   city(char *s)        { strcpy(rec._city,s); dirty=TRUE; } 
  203.     void   count(char *s)       { strcpy(rec._count,s); dirty=TRUE; } 
  204.     void   zip(char *s)         { strcpy(rec._zip,s); dirty=TRUE; } 
  205.     void   tel(char *s)         { strcpy(rec._tel,s); dirty=TRUE; } 
  206.     void   update(char *s)      { _update=s; dirty=TRUE; } 
  207.     void   birth(char *s)       { _birth=s; dirty=TRUE; } 
  208.     void   relation(char *s)    { strcpy(rec._relation,s); dirty=TRUE; } 
  209.     void   info(char *s)        { strcpy(rec._info,s); dirty=TRUE; } 
  210.  
  211. };